# coding=utf-8
from django.shortcuts import render_to_response
from apps.news.models import News
from apps.research.views import head_group

#-----Home-----
MAX_ITEMS = 3

def home(request, lang):
    if lang != 'en' and lang != 'zh':
        return render_to_response('404.html', {'error': 'Unkown language error'})
#   过滤Draft和没有图片的news
    news_list = list(News.objects.filter(news_status=False).exclude(news_cover=''))
    return render_to_response('index.html', {
        'lang': lang,
        'url_en': '/en/index/',
        'url_zh': '/zh/index/',
        'head_group_list': head_group(),
        'news_list': news_list[:MAX_ITEMS]})

#-----About-----
def about(request, lang):
    if lang == 'en':
        return render_to_response('about_en.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/',
            'url_zh': '/zh/about/'})
    elif lang == 'zh':
        return render_to_response('about_zh.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/',
            'url_zh': '/zh/about/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

def infrastructure(request, lang):
    if lang == 'en':
        return render_to_response('about/infrastructure_en.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/infrastructure/',
            'url_zh': '/zh/about/infrastructure/'})
    elif lang == 'zh':
        return render_to_response('about/infrastructure_zh.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/infrastructure/',
            'url_zh': '/zh/about/infrastructure/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

def mission(request, lang):
    if lang == 'en':
        return render_to_response('about/mission_en.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/mission/',
            'url_zh': '/zh/about/mission/'})
    elif lang == 'zh':
        return render_to_response('about/mission_zh.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/mission/',
            'url_zh': '/zh/about/mission/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

def overview(request, lang):
    if lang == 'en':
        return render_to_response('about/overview_en.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/overview/',
            'url_zh': '/zh/about/overview/'})
    elif lang == 'zh':
        return render_to_response('about/overview_zh.html', {
            'current_item': 'about',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/about/overview/',
            'url_zh': '/zh/about/overview/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

#-----Contact-----
def contact(request, lang):
    if lang == 'en':
        return render_to_response('contact_en.html', {
            'current_item': 'contact',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/contact/',
            'url_zh': '/zh/contact/'})
    elif lang == 'zh':
        return render_to_response('contact_zh.html', {
            'current_item': 'contact',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/contact/',
            'url_zh': '/zh/contact/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

#-----Education-----
def education(request, lang):
    if lang == 'en':
        return render_to_response('education_en.html', {
            'current_item': 'education',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/education/',
            'url_zh': '/zh/education/'})
    elif lang == 'zh':
        return render_to_response('education_zh.html', {
            'current_item': 'education',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/education/',
            'url_zh': '/zh/education/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

def edu_prog(request, lang):
    if lang == 'en':
        return render_to_response('education/edu_prog_en.html', {
            'current_item': 'education',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/education/edu-prog/',
            'url_zh': '/zh/education/edu-prog/'})
    elif lang == 'zh':
        return render_to_response('education/edu_prog_zh.html', {
            'current_item': 'education',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/education/edu-prog/',
            'url_zh': '/zh/education/edu-prog/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

def adv_edu_prog(request, lang):
    if lang == 'en':
        return render_to_response('education/adv_edu_prog_en.html', {
            'current_item': 'education',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/education/adv-edu-prog/',
            'url_zh': '/zh/education/adv-edu-prog/'})
    elif lang == 'zh':
        return render_to_response('education/adv_edu_prog_zh.html', {
            'current_item': 'education',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/education/adv-edu-prog/',
            'url_zh': '/zh/education/adv-edu-prog/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})

#-----FAQ-----
def faq(request, lang):
    if lang == 'en':
        return render_to_response('faq_en.html', {
            'current_item': 'faq',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/faq/',
            'url_zh': '/zh/faq/'})
    elif lang == 'zh':
        return render_to_response('faq_zh.html', {
            'current_item': 'faq',
            'lang': lang,
            'head_group_list': head_group(),
            'url_en': '/en/faq/',
            'url_zh': '/zh/faq/'})
    else:
        return render_to_response('404.html', {'error': 'Unkown language error'})
